package com.example.HelloWorld;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "SecondServlet2", value = "/secondServlet2")
public class SecondServlet2 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String studentName = request.getParameter("studentName");
        String age = request.getParameter("age");
        request.setAttribute("studentName",studentName);
        request.setAttribute("age",age);

        String languages[] = request.getParameterValues("languages");
        if(languages==null){
            request.setAttribute("languages0","暂无精通语言");
        }else{
            for (int i = 0; i < languages.length; i++) {
                request.setAttribute("languages" + i, languages[i]);
                System.out.println("languages" + i);
            }
        }

        if(request.getParameter("sex")!=null){

            if (Integer.parseInt(request.getParameter("sex"))==0){
                request.setAttribute("sex","男");
            }else if(Integer.parseInt(request.getParameter("sex"))==1){
                request.setAttribute("sex","女");
            }else {
                request.setAttribute("sex","保密");
            }
        }else{
            request.setAttribute("sex","未选择任何性别");
        }
        String birthday = request.getParameter("birthday");
        request.setAttribute("birthday",birthday);
        request.getRequestDispatcher("login1.jsp").forward(request,response);



    }
}
